# 构建阶段
FROM golang:1.21-alpine AS builder

WORKDIR /app

# 安装依赖
COPY go.mod go.sum ./
RUN go mod download

# 复制源代码
COPY . .

# 构建应用
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .

# 运行阶段
FROM alpine:latest

RUN apk --no-cache add ca-certificates tzdata wget curl
WORKDIR /root/

# 从构建阶段复制二进制文件
COPY --from=builder /app/main .
COPY --from=builder /app/assets ./assets
COPY --from=builder /app/config ./config

# 创建必要的目录
RUN mkdir -p /app/logs /app/uploads /app/avatars

# 设置时区
ENV TZ=Asia/Shanghai

EXPOSE 9292

CMD ["./main"]
